var e = getApp(), t = require("../../utils/util.js"), o = null, a = {
    history: [],
    sum: 0,
    weitou: 0,
    dietou: 0
};

Page({
    data: {
        res: a,
        canUserSetMoreHistory: !1,
        videoAdLoading: !1,
        bnAd_03: e.ad.bnAd_03,
        sharing: !1
    },
    videoAdLoad: function() {
        var t = this;
        if (1 != this.data.videoAdLoading) return null != o ? (this.setData({
            videoAdLoading: !0
        }), this.videoAdShow()) : void (wx.createRewardedVideoAd && (this.setData({
            videoAdLoading: !0
        }), (o = wx.createRewardedVideoAd({
            adUnitId: e.ad.jlAd_04,
            multiton: !0
        })).onLoad(function() {
            1 == t.data.videoAdLoading && t.videoAdShow();
        }), o.onError(function(e) {
            o = null, t.setData({
                videoAdLoading: !1
            });
        }), o.onClose(function(e) {
            t.setData({
                videoAdLoading: !1
            }), e && e.isEnded && (t.setData({
                canUserSetMoreHistory: !0
            }), wx.setStorageSync("canUserSetMoreHistory", {
                value: !0,
                time: Date.parse(new Date())
            }));
        })));
    },
    onShow: function() {
        var e = t.getHistory(), o = wx.getStorageSync("canUserSetMoreHistory"), a = !1;
        "" != o && (Date.parse(new Date()) - o.time) / 1e3 < 86400 && (a = !0), this.setData({
            sharing: !1,
            res: e,
            canUserSetMoreHistory: a
        });
    },
    remove: function() {
        t.removeHistory(), this.setData({
            res: a
        });
    },
    onShareAppMessage: function(e) {
        return this.setData({
            sharing: !0
        }), {
            title: "我在KTV喝酒摇骰子的战果"
        };
    },
    videoAdShow: function() {
        var e = this;
        null != o && o.show().catch(function() {
            e.setData({
                videoAdLoading: !1
            }), o.load().then(function() {
                return o.show();
            }).catch(function(e) {
                t.videoAdErrCodeHandle(e);
            });
        });
    }
});